package com.iss.umservice.manager.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iss.iframework.common.errcode.AppRuntimeException;
import com.iss.iframework.util.StringUtil;
import com.iss.umservice.bean.ResourceBean;
import com.iss.umservice.bean.RoleBean;
import com.iss.umservice.dao.ResourceDao;
import com.iss.umservice.dao.RoleDao;
import com.iss.umservice.manager.ResourceManager;

/**
 * ��Դҵ���߼�����
 * 
 * @author suxiaoping
 * @date 2012-8-31
 */
@Service
public class ResourceManagerImpl implements ResourceManager
{
    private final Logger logger = LoggerFactory.getLogger(getClass());
    
    @Autowired
    private ResourceDao resourceDao;
    
    /**
     * ��ѯ����Դ
     * 
     * @param roleName //��Դ���
     * @param systemId //ϵͳID
     * @return  list
     */
    public List<ResourceBean> queryResourceInfos(ResourceBean resourceBean, int offset, int row) throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post resourceName request.",
                    resourceBean.getResourceName());
        }
        
        List<ResourceBean> beanList = resourceDao.queryResourceInfos(resourceBean,
                offset,
                row);
        
        return beanList;
        
    }
    
    /**
     * ���ID�Ĳ�ѯ��Դ
     * 
     * @param resourceId //��ԴId
     * @return  resourceBean
     */
    public ResourceBean queryResourceInfoById(String resourceId)
            throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post resourceId request.",
                    resourceId);
        }
        
        ResourceBean resourceInfo = resourceDao.queryResourceInfoById(resourceId);
        
        return resourceInfo;
        
    }
    
    /**
     * ������Դ��Ϣ
     * 
     * @param resourceBean //��Դ��Ϣ
     * @return  
     */
    public void addResourceInfo(ResourceBean resourceBean)
            throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post resourceBean request.",
                    resourceBean);
        }
        
        resourceDao.addResourceInfo(resourceBean);
        
    }
    
    /**
     * ɾ����Դ��Ϣ
     * 
     * @param resourceId //��ԴID
     * @return  
     */
    public void delResourceInfoById(String resourceId)
            throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post resourceId request.",
                    resourceId);
        }
        
        //����ɾ��
        if (null != resourceId && !"".equals(resourceId))
        {
            String[] ids = resourceId.split(";");
            
            for (int i = 0; i < ids.length; i++)
            {
                //ɾ����Դ
                resourceDao.delResourceInfoById(ids[i]);
            }
        }
    }
    
    /**
     * �޸���Դ��Ϣ
     * 
     * @param resourceBean //��Դ��Ϣ
     * @return  
     */
    public void updateResourceInfo(ResourceBean resourceBean)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post resourceBean request.",
                    resourceBean);
        }

        
        resourceDao.updateResourceInfo(resourceBean);
    }
    
    /**
     * �������ͳ����Դ
     * 
     * @param resourceName ��Դ���
     * @return int
     */
    public int countResourceInfo(ResourceBean resourceBean)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post resourceName request.",
                    resourceBean.getResourceName());
        }
        
        return resourceDao.countResourceInfo(resourceBean);
    }

    public String checkResourceName(String resourceName)
    {
        // TODO Auto-generated method stub
        return resourceDao.checkResourceName(resourceName);
    }
    
}
